import asyncio
import json
from playwright.async_api import async_playwright

async def run():
    async with async_playwright() as p:
        browser = await p.chromium.launch(headless=False)  # 手动登录时要开界面
        context = await browser.new_context()

        page = await context.new_page()
        # 游戏','社交','娱乐','效率','购物','教育','健康健身','商务','生活','金融','旅行'
        await page.goto("https://app.sensortower-china.com/top-charts?country=US&category=0&date=2025-09-01&device=iphone&os=ios")

        print("请手动完成登录，然后按 Enter...")
        input()

        # 保存 cookies 和 localStorage
        cookies = await context.cookies()
        storage = await context.storage_state()
        with open("storage.json", "w", encoding="utf-8") as f:
            f.write(json.dumps(storage))

        print("登录状态已保存到 storage.json")
        await browser.close()

asyncio.run(run())
